home *** CD-ROM | disk | FTP | other *** search
/ Apple II Magazines (PO) / Nibble Volume 10, No. 05 (1989-05)(MicroSPARC)(Side A)[a].zip / Nibble Volume 10, No. 05 (1989-05)(MicroSPARC)(Side A)[a].po / RESET.S.txt < prev    next >
Text File  |  1996-12-24  |  15KB  |  330 lines

  1. **************************
  2. *  RESET.OBJ SOURCE CODE *
  3. *  BY KENN SCRIBNER      *
  4. *  COPYRIGHT (C) 1989    *
  5. *  MICROSPARC, INC.      *
  6. *  CONCORD, MA 01742     *
  7. **************************
  8. *
  9. *
  10. *  ORCA/M 4.1 Assembler
  11. *
  12.          ORG    $6EC7
  13.          KEEP   RESET
  14. RESET    START
  15. ;...............................................................
  16. ;
  17. ; Program EQUates.
  18. ;...............................................................
  19. CSWL     EQU   $36                      ;monitor character output hook
  20. KSWL     EQU   $38                      ;monitor character input hook
  21. VBL1     EQU   $3C                      ;temporary storage location
  22. VBL2     EQU   $3D                      ;temporary storage location
  23. VBL3     EQU   $3E                      ;temporary storage location
  24. VBL4     EQU   $3F                      ;temporary storage location
  25. A1L      EQU   $3C                      ;source starting address for MOVE
  26. A2L      EQU   $3E                      ;source ending address for MOVE
  27. A4L      EQU   $42                      ;destination address for MOVE
  28. LINNUM   EQU   $50                      ;ASoft line number in progress
  29. CURLIN   EQU   $75                      ;ASoft line number in progress
  30. VARPNT   EQU   $83                      ;pointer to ASoft variable data
  31. TXTPTR   EQU   $B8                      ;current ASoft token's address
  32. ERRPOS   EQU   $DC                      ;temporary storage for TXTPTR
  33. INBUFR   EQU   $200                     ;DOS command input buffer
  34. RSTVCTL  EQU   $3F2                     ;reset vector low byte
  35. RSTVCTH  EQU   $3F3                     ;reset vector high byte
  36. RSTVCTV  EQU   $3F4                     ;reset vector power-up validation byte
  37. ERROR    EQU   $D412                    ;ASoft error handler, errnum in xreg
  38. STKINI   EQU   $D683                    ;restore ASoft's stack pointer
  39. STXTPT   EQU   $D697                    ;reset TXTPTR to beginning of program
  40. NEWSTT   EQU   $D7D2                    ;execute ASoft program from TXTPTR
  41. GETLIN   EQU   $D941                    ;find line in LINNUM in memory
  42. PTRGET   EQU   $DFE3                    ;find/create simple variable in memory
  43. GIVAYF   EQU   $E2F2                    ;convert integer in A,Y to floating pt.
  44. GETADR   EQU   $E752                    ;convert floating pt. number to integer
  45. MOVFM    EQU   $EAF9                    ;unpack variable data and move to FAC
  46. MOVMF    EQU   $EB2B                    ;pack FAC data and move to variable
  47. SETHMEM1 EQU   $F28E                    ;calculate and set HIMEM from LINNUM
  48. MOVE     EQU   $FE2C                    ;monitor memory move routine
  49.  
  50. ;...............................................................
  51. ;
  52. ; ProDOS and BASIC.SYSTEM EQUates.
  53. ;...............................................................
  54.  
  55. DOSCMD   EQU   $BE03                    ;execute DOS command stored at $200
  56. ERROUT   EQU   $BE09                    ;BASIC.SYSTEM error handler
  57. VECTOUT  EQU   $BE30                    ;BASIC.SYSTEM output link
  58. VECTIN   EQU   $BE32                    ;BASIC.SYSTEM input link
  59. GETBUFR  EQU   $BEF5                    ;reserve x pages above HIMEM, x in areg
  60. KVERSION EQU   $BFFF                    ;ProDOS Kernel Version
  61.  
  62. ;...............................................................
  63. ;
  64. ; DOS 3.3 EQUates.
  65. ;...............................................................
  66.  
  67. CONNECT  EQU   $3EA                     ;DOS 3.3 I/O vector reconnection routine
  68. MAXFILES EQU   $A258                    ;DOS 3.3 MAXFILES command
  69. CLOSE    EQU   $A316                    ;close all open DOS 3.3 files
  70.  
  71. ;...............................................................
  72. ;
  73. ; Set up SV variable.
  74. ;...............................................................
  75.          LDA   #>SETUP                  ;variable data high byte
  76.          STA   VBL1                     ;store it for subroutine
  77.          LDA   #<SETUP                  ;variable data low byte
  78.          STA   VBL2                     ;store it
  79.          LDA   #>SVVBL                  ;variable name's location high byte
  80.          STA   VBL3                     ;store it
  81.          LDA   #<SVVBL                  ;variable name's location low byte
  82.          STA   VBL4                     ;store it
  83.          JSR   SETVBL                   ;set up the variable
  84.          RTS                            ;done, let user initialize reset pgm
  85. ;...............................................................
  86. ;
  87. ; Set up RE variable.
  88. ;...............................................................
  89. SETUP    LDA   #$03                     ;ASoft equivalent of LET RE = 1000
  90.          STA   VBL1
  91.          LDA   #$E8                     ; ($03E8 = 1000 decimal)
  92.          STA   VBL2
  93.          LDA   #>REVBL                  ;NOTE:  this overwrites any previous
  94.          STA   VBL3                     ; RE values!
  95.          LDA   #<REVBL
  96.          STA   VBL4
  97.          JSR   SETVBL                   ;create/change variable
  98.          LDA   CSWL                     ;save I/O links so DOS may be recon-
  99.          STA   RST+1                    ; nected after a reset.
  100.          LDA   CSWL+1                   ;saving output links
  101.          STA   RST+5
  102.          LDA   KSWL                     ;saving input links
  103.          STA   RST+9
  104.          LDA   KSWL+1
  105.          STA   RST+13
  106. CHKDOS   LDA   KVERSION                 ;check which DOS we're running
  107.          BMI   DOS33                    ;running DOS 3.3
  108. PDOS     LDA   #$01                     ;want 1 page (256 bytes) of reserved
  109.          JSR   GETBUFR                  ; space (moves HIMEM and protects us)
  110.          BCC   FIXPGM                   ;enough memory, okay to relocate pgm
  111. MEMERR   LDX   #$4D                     ;?OUT OF MEMORY error
  112.          JMP   ERROR                    ;not enough memory, flag user
  113. ;...............................................................
  114. ;
  115. ; This code "fixes" our program, since we don't know beforehand where
  116. ;  BASIC.SYSTEM will want it moved.
  117. ;...............................................................
  118. FIXPGM   STA   FIX1+1                   ;we need to correct any absolute
  119.          STA   FIX2+1                   ; addresses to properly relocate code
  120.          STA   CLSLOOP+2
  121.          STA   SETVECT+6                ;new reset vector's value (high byte)
  122.          STA   A4L+1                    ;high byte of memory to relocate to
  123.          LDA   #$BE
  124.          STA   KILLVECT+6               ;point KV to $BE00
  125.          LDA   #$00                     ;low byte of memory to relocate to
  126.          STA   A4L
  127.          STA   KILLVECT+1
  128.          LDA   #<RST                    ;beginning of program to be moved
  129.          STA   A1L
  130.          LDA   #>RST
  131.          STA   A1L+1
  132.          LDA   #<END                    ;ending of program to be moved
  133.          STA   A2L
  134.          LDA   #>END
  135.          STA   A2L+1
  136.          LDY   #$00
  137.          JSR   MOVE                     ;move program
  138. ;...............................................................
  139. ;
  140. ; Set up KV and SV, kill vector and set vector for ProDOS version.
  141. ;...............................................................
  142.          LDA   FIX1+1                   ;get high byte of set routine
  143.          STA   VBL1                     ; (corrected for BASIC.SYSTEM move)
  144.          LDA   #<KILLVECT
  145.          STA   VBL2
  146.          LDA   #>KVVBL                  ;find variable's name
  147.          STA   VBL3
  148.          LDA   #<KVVBL
  149.          STA   VBL4
  150.          JSR   SETVBL                   ;create/change KV
  151.          LDA   FIX1+1                   ;get high byte of set routine
  152.          STA   VBL1                     ; (corrected for BASIC.SYSTEM move)
  153.          LDA   #<SETVECT
  154.          STA   VBL2
  155.          LDA   #>SVVBL                  ;find variable's name
  156.          STA   VBL3
  157.          LDA   #<SVVBL
  158.          STA   VBL4
  159.          JSR   SETVBL                   ;create/change SV
  160.          BCC   FIXVECT                  ;twiddle reset vector
  161. ;...............................................................
  162. ;
  163. ; DOS 3.3 version.  We always know the reset program will load at
  164. ;  $9600, so we won't need to fix it.
  165. ;...............................................................
  166. DOS33    LDA   #$01                     ;MAXFILES = 1 command
  167.          JSR   MAXFILES
  168.          LDA   #$00                     ;set HIMEM to $9600
  169.          STA   LINNUM
  170.          LDA   #$96
  171.          STA   LINNUM+1
  172.          JSR   SETHMEM1                 ;calculate and set new HIMEM
  173.          LDA   #$00                     ;low byte of memory to relocate to
  174.          STA   A4L
  175.          LDA   #$96                     ;high byte of memory to relocate to
  176.          STA   A4L+1
  177.          LDA   #<RST                    ;beginning of program to be moved
  178.          STA   A1L
  179.          LDA   #>RST
  180.          STA   A1L+1
  181.          LDA   #<END                    ;ending of program to be moved
  182.          STA   A2L
  183.          LDA   #>END
  184.          STA   A2L+1
  185.          LDY   #$00
  186.          JSR   MOVE                     ;move program
  187.          LDA   #$96                     ;get high byte of kill routine
  188.          STA   VBL1
  189.          LDA   #<KILLVECT
  190.          STA   VBL2
  191.          LDA   #>KVVBL                  ;find variable's name
  192.          STA   VBL3
  193.          LDA   #<KVVBL
  194.          STA   VBL4
  195.          JSR   SETVBL                   ;create/change KV
  196.          LDA   #$96                     ;get high byte of set routine
  197.          STA   VBL1
  198.          LDA   #<SETVECT
  199.          STA   VBL2
  200.          LDA   #>SVVBL                  ;find variable's name
  201.          STA   VBL3
  202.          LDA   #<SVVBL
  203.          STA   VBL4
  204.          JSR   SETVBL                   ;create/change SV
  205. ;...............................................................
  206. ;
  207. ; Set up reset vector.
  208. ;...............................................................
  209. FIXVECT  LDA   #$00                     ;low byte
  210.          STA   RSTVCTL
  211. FIX1     LDA   #$96                     ;(corrected) high byte
  212.          STA   RSTVCTH
  213.          EOR   #$A5                     ;twiddle power-up byte
  214.          STA   RSTVCTV
  215.          RTS                            ;done, ASoft reset enabled
  216. ;...............................................................
  217. ;
  218. ; Routine to create/find ASoft variables.
  219. ;...............................................................
  220. SETVBL   LDA   TXTPTR                   ;save present location in ASoft pgm
  221.          STA   ERRPOS
  222.          LDA   TXTPTR+1
  223.          STA   ERRPOS+1
  224.          LDA   VBL3                     ;retrieve high byte of our variable
  225.          STA   TXTPTR+1
  226.          LDA   VBL4                     ;retrieve low byte of our variable
  227.          STA   TXTPTR
  228.          JSR   PTRGET                   ;find/create variable
  229.          LDA   VBL1                     ;retrieve high byte's value
  230.          LDY   VBL2                     ;retrieve low data byte's value
  231.          JSR   GIVAYF
  232.          LDX   VARPNT
  233.          LDY   VARPNT+1
  234.          JSR   MOVMF
  235.          LDA   ERRPOS                   ;restore actual location of ASoft pgm
  236.          STA   TXTPTR
  237.          LDA   ERRPOS+1
  238.          STA   TXTPTR+1
  239.          CLC                            ;clear carry to force branch on return
  240.          RTS                            ;done!
  241. ;...............................................................
  242. ;
  243. ; Set and Kill variable names.
  244. ;...............................................................
  245.  
  246. SVVBL    DC    H'53 56 00'              ;"SV"
  247. KVVBL    DC    H'4B 56 00'              ;"KV"
  248.  
  249. ;...............................................................
  250. ;
  251. ; Reset routine.
  252. ;...............................................................
  253. RST      LDA   #$F0                     ;reconnect default I/O links
  254.          STA   CSWL                     ;character output
  255.          LDA   #$FD                     ; (default 40 columns, COUT = $FDF0)
  256.          STA   CSWL+1
  257.          LDA   #$1B                     ;character input
  258.          STA   KSWL                     ; (default keyboard)
  259.          LDA   #$FD
  260.          STA   KSWL+1
  261.          LDA   KVERSION                 ;are we running ProDOS?
  262.          BMI   RSTDOS33                 ;no, reset for DOS 3.3
  263.          LDA   #$F0                     ;set default BASIC.SYSTEM global vectors
  264.          STA   VECTOUT                  ; (character output --> $FDF0, or COUT)
  265.          LDA   #$FD
  266.          STA   VECTOUT+1
  267.          LDA   #$1B                     ; (character input --> $FD1B, or KEYIN)
  268.          STA   VECTIN
  269.          LDA   #$FD
  270.          STA   VECTIN+1
  271. CLSFILE  LDX   #$00                     ;have BASIC.SYSTEM close all open files
  272. CLSLOOP  LDA   CLSCMD,X                ;(we have BASIC.SYSTEM CLOSE files...
  273.          BEQ   CLSALL                   ;...rather than the ProDOS MLI 'cause...
  274.          STA   INBUFR,X                 ;...BASIC.SYSTEM does some other...
  275.          INX                            ;...housekeeping the MLI doesn't)
  276.          BNE   CLSLOOP
  277. CLSCMD   DC    H'C3 CC CF D3 C5 8D 00'  ;"CLOSE", with carriage return and $00
  278. CLSALL   JSR   DOSCMD
  279.          BCC   READVBL
  280.          LDA   #$15                     ;FILE(S) STILL OPEN error
  281.          JMP   ERROUT
  282. RSTDOS33 JSR   CONNECT                  ;reconnect DOS 3.3
  283.          JSR   CLOSE                    ;close all open files
  284. READVBL  LDA   #<REVBL                  ;retrieve line number from RE
  285.          STA   TXTPTR
  286. FIX2     LDA   #$96                     ;byte will be corrected for ProDOS call
  287.          STA   TXTPTR+1
  288.          JSR   PTRGET                   ;find variable data
  289.          JSR   MOVFM                    ;move it to the FAC
  290.          JSR   GETADR                   ;convert it to integer (in LINNUM)
  291.          LDA   LINNUM+1                 ;get high byte of line number
  292.          STA   CURLIN+1                 ;store it for execution
  293.          LDA   LINNUM                   ;get low byte of line num
  294.          STA   CURLIN                   ;store it for execution
  295.          JSR   STKINI                   ;restore stack
  296.          JSR   STXTPT                   ;reset TXTPTR to beginning of program
  297.          JSR   GETLIN                   ;find our new line in memory
  298.          JMP   NEWSTT                   ;start execution at new line number
  299. ;...............................................................
  300. ;
  301. ; Restore variable name.
  302. ;...............................................................
  303.  
  304. REVBL    DC    H'52 45 00'              ;"RE"
  305.  
  306. ;...............................................................
  307. ;
  308. ; Routine to re-enable the reset program.
  309. ;...............................................................
  310. SETVECT  LDA   #$00                     ;point reset vector to $9600
  311.          STA   RSTVCTL
  312.          LDA   #$96                     ;will be modified for ProDOS version
  313.          STA   RSTVCTH
  314.          EOR   #$A5
  315.          STA   RSTVCTV
  316.          RTS
  317.  
  318. ;...............................................................
  319. ;
  320. ; Routine to disable the reset program.
  321. ;...............................................................
  322. KILLVECT LDA   #$BF                     ;restore reset vector to default values
  323.          STA   RSTVCTL                  ;($9DBF for DOS 3.3)
  324.          LDA   #$9D                     ;($BE00 for BASIC.SYSTEM, which will...
  325.          STA   RSTVCTH                  ;...be inserted here before this code...
  326.          EOR   #$A5                     ;...is relocated)
  327.          STA   RSTVCTV
  328. END      RTS
  329.          END
  330.